let needLogin = [
    "/pages/tab/index",
]
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"];
list.forEach(item => { //用遍历的方式分别为,uni.navigateTo,uni.redirectTo,uni.reLaunch,uni.switchTab这4个路由方法添加拦截器
    uni.addInterceptor(item, {
        invoke(e) { // 调用前拦截
            if (e.url.includes('login')) {
                return true
            } else {
                if (!uni.getStorageSync("token")) {
                    return true
                }
                const statusObj = uni.getStorageSync('statusObj')
                console.log('statusObj', statusObj.pay)
                if (!statusObj.pay) {
                    if (!e.url.includes('user-info')) {
                        uni.navigateTo({
                            url: '/pages/user-info/user-info'
                        })
                        return false

                    } else {
                        return true
                    }

                } else if(!statusObj.address) {
                    if (!e.url.includes('address/add')) {
                        uni.navigateTo({
                            url: '/pages/address/add'
                        })
                        return false

                    } else {
                        return true
                    }
                }
            }
            return true
        },
        fail(err) { // 失败回调拦截
            console.log(err);
        },
    })
})
